	
	
	var familyTable = function(dataList){
		
		return notPageTableByArrayData('#datatables',dataList,listArr,true);
		
	} 
	
	

$(function(){
	
	
	$.ajax({
		url : webroot+ "/memberFamily/getMemberFamilyPageData.do",
		data : {'memberId':$("#memberId").val()},
		type : 'POST',
		dataType : 'json',
		success : function(dataResult) {
			
			familyTable(dataResult.dataList);
		}
	});
	
	
    
  //单击行选中事件
    $('#datatables tbody').on('click', 'tr', function () {
        var table = $('#datatables').DataTable();
        var data = table.row(this).data();
        if ($(this).hasClass('selected')) {
            $(this).removeClass('selected');
            $('#check' + data.id).prop("checked", false);
        } else {
            $(this).addClass('selected');
            $('#check' + data.id).prop("checked", true);
        }
    });
    

    
  //全选事件
    $(".checkall").click(function () {
        var check = $(this).prop("checked");
        $(".checkchild").prop("checked", check);
        var cells = new Array();
        $('#datatables tbody tr').each(function () {
            if (check) {
                $(this).addClass('selected');
            } else {
                $(this).removeClass('selected');
            }
        });
    });
    
    $(".familyAdd").on('click',function(){
    	
    	layer.open({
		  type : 2,
		  title: '新增', 
		  skin: 'demo-class',
		  offset : '5%',
		  content: webroot + "/memberFamily/toSaveMemberFamilyForm.do?memberId="+$("#memberId").val(),
		  area: ['700px','90%']
		});
    	
    });
    
});

function toEditForm(id){
	
	layer.open({
		  type : 2,
		  title: '修改', 
		  skin: 'demo-class',
		  offset : '5%',
		  content: webroot + "/memberFamily/toEditMemberFamilyForm.do?id="+id,
		  area: ['700px','90%']
		});
}



function familyDel(id){
	
	if (confirm("确定要删除吗？")) {
    	$.ajax({
    		url : webroot + '/memberFamily/deleteMemberFamilyById.do',
    		data : {'id':id},
    		type : 'post',
    		dataType : 'json',
    		success : function(result){
    			layer.msg(result.msg);
    			
    			if(result.type=='2'){
    				$.ajax({
    					url : webroot+ "/memberFamily/getMemberFamilyPageData.do",
    					data : {'memberId':$("#memberId").val()},
    					type : 'POST',
    					dataType : 'json',
    					success : function(dataResult) {
    						familyTable(dataResult.dataList);
    					}
    				});
    			}
    			
    		}
    	});
    }
}

